using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace MyCityCab.Core
{
	/// <summary>
	/// Strongly-typed collection for the JourneyComment class.
	/// </summary>
	[Serializable]
	public partial class JourneyCommentCollection : ActiveList<JourneyComment, JourneyCommentCollection> 
	{	   
		public JourneyCommentCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the JourneyComment table.
	/// </summary>
	[Serializable]
	public partial class JourneyComment : ActiveRecord<JourneyComment>
	{
		#region .ctors and Default Settings
		
		public JourneyComment()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public JourneyComment(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public JourneyComment(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public JourneyComment(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("JourneyComment", TableType.Table, DataService.GetInstance("MyCityCab"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarJourneyId = new TableSchema.TableColumn(schema);
				colvarJourneyId.ColumnName = "Journey_Id";
				colvarJourneyId.DataType = DbType.Int32;
				colvarJourneyId.MaxLength = 0;
				colvarJourneyId.AutoIncrement = false;
				colvarJourneyId.IsNullable = false;
				colvarJourneyId.IsPrimaryKey = true;
				colvarJourneyId.IsForeignKey = true;
				colvarJourneyId.IsReadOnly = false;
				colvarJourneyId.DefaultSetting = @"";
				
					colvarJourneyId.ForeignKeyTableName = "Journey";
				schema.Columns.Add(colvarJourneyId);
				
				TableSchema.TableColumn colvarCommentId = new TableSchema.TableColumn(schema);
				colvarCommentId.ColumnName = "Comment_Id";
				colvarCommentId.DataType = DbType.Int32;
				colvarCommentId.MaxLength = 0;
				colvarCommentId.AutoIncrement = false;
				colvarCommentId.IsNullable = false;
				colvarCommentId.IsPrimaryKey = true;
				colvarCommentId.IsForeignKey = true;
				colvarCommentId.IsReadOnly = false;
				colvarCommentId.DefaultSetting = @"";
				
					colvarCommentId.ForeignKeyTableName = "Comment";
				schema.Columns.Add(colvarCommentId);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["MyCityCab"].AddSchema("JourneyComment",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("JourneyId")]
		public int JourneyId 
		{
			get { return GetColumnValue<int>("Journey_Id"); }

			set { SetColumnValue("Journey_Id", value); }

		}

		  
		[XmlAttribute("CommentId")]
		public int CommentId 
		{
			get { return GetColumnValue<int>("Comment_Id"); }

			set { SetColumnValue("Comment_Id", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Comment ActiveRecord object related to this JourneyComment
		/// 
		/// </summary>
		public MyCityCab.Core.Comment Comment
		{
			get { return MyCityCab.Core.Comment.FetchByID(this.CommentId); }

			set { SetColumnValue("Comment_Id", value.Id); }

		}

		
		
		/// <summary>
		/// Returns a Journey ActiveRecord object related to this JourneyComment
		/// 
		/// </summary>
		public MyCityCab.Core.Journey Journey
		{
			get { return MyCityCab.Core.Journey.FetchByID(this.JourneyId); }

			set { SetColumnValue("Journey_Id", value.Id); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varJourneyId,int varCommentId)
		{
			JourneyComment item = new JourneyComment();
			
			item.JourneyId = varJourneyId;
			
			item.CommentId = varCommentId;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varJourneyId,int varCommentId)
		{
			JourneyComment item = new JourneyComment();
			
				item.JourneyId = varJourneyId;
				
				item.CommentId = varCommentId;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string JourneyId = @"Journey_Id";
			 public static string CommentId = @"Comment_Id";
						
		}

		#endregion
	}

}

